package com.yy.jhl.widget;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.yy.jhl.R;

/**
 * 通用ListView(带无数据界面显示，无网或者数据失败界面显示)
 * Created by Ellis.Li on 2017/8/18.
 */

public class FullListView extends RelativeLayout {
    Context mContext;
    private PullToRefreshListView pullListView;
    private ListView listView;
    private LinearLayout noDataView;
    private TextView refreshText;

    public FullListView(Context context) {
        super(context);
        initView(context);
    }

    public FullListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public FullListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    /**
     * 初始化
     * @param context
     */
    private void initView(Context context){
        mContext = context;
        View view = LayoutInflater.from(mContext).inflate(R.layout.full_list_view,null);
        pullListView = (PullToRefreshListView) view.findViewById(R.id.refreshListView);
        //默认不刷新
        pullListView.setMode(PullToRefreshBase.Mode.DISABLED);
        listView = pullListView.getRefreshableView();
        listView.setDividerHeight(2);
        noDataView = (LinearLayout) view.findViewById(R.id.no_data_view);
        addView(view,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }

    /**
     * 设置刷新模式
     * @param mode
     */
    public void setRefreshMode(PullToRefreshBase.Mode mode){
        pullListView.setMode(mode);
    }

    /**
     * 获取刷新列表控件
     * @return
     */
    public PullToRefreshListView getPullListView() {
        return pullListView;
    }

    /**
     * 显示无数据界面
     */
    public void showNoDataView(){
        noDataView.setVisibility(VISIBLE);
        pullListView.setVisibility(VISIBLE);
    }
    /**
     * 隐藏无数据界面
     */
    public void hideNoDataView(){
        noDataView.setVisibility(GONE);
        pullListView.setVisibility(VISIBLE);
    }

    /**
     * 显示数据界面
     */
    public void showDataView(){
        pullListView.setVisibility(VISIBLE);
        noDataView.setVisibility(GONE);
    }

    /**
     * 显示无网络界面
     */
    public void showNoNetworkView(){
        pullListView.setVisibility(GONE);
        noDataView.setVisibility(GONE);
    }
    /**
     * 设置分割线颜色
     */
    public void setDividerColor(int color,int height){
        listView.setDivider(new ColorDrawable(color));
        listView.setDividerHeight(height);
    }


}
